// VoterSurveyEconomics
log using VoterSurveyEconomics.log, replace
use "C:\Users\sbstjp\OneDrive - Cardiff University\voter_panel.dta" // Democracy Fund Voter Study Group. VIEWS OF THE ELECTORATE RESEARCH SURVEY. Washington, D.C. https://www.voterstudygroup.org/.  Date accessed: March 09, 2025.

// Create social justice scale
*Delete missing
replace ft_blm_2020Sep=. if ft_blm_2020Sep>100
replace reparations_2020Sep=. if reparations_2020Sep>2
replace defundpolice_2020Sep=. if defundpolice_2020Sep>2 
replace police_threat_2020Sep=. if police_threat_2020Sep>2
replace usa_founders_2020Sep=. if usa_founders_2020Sep>2
replace internetharass_dem_2020Sep=. if internetharass_dem_2020Sep==9

*Reverse coding so social justice values are coded high
foreach var in reparations_2020Sep defundpolice_2020Sep usa_founders_2020Sep {
    qui sum `var'
    local max_value = r(max)
    gen r`var' = `max_value' - `var'
}

*Standardize items in the scale from 1-2 - this avoids 0, for reasons outlined in next step
foreach var in ft_blm_2020Sep rreparations_2020Sep rdefundpolice_2020Sep rusa_founders_2020Sep police_threat_2020Sep internetharass_dem_2020Sep {
    summarize `var'
    gen s`var' = 1 + (`var' - r(min)) / (r(max) - r(min))
}

*At this stage, the scale has a Cronbach's alpha of 0.83

* Replace missing values with 0 for the specified variables - this is necessary as Stata doesn't add up missing values
foreach var in sft_blm_2020Sep srreparations_2020Sep srdefundpolice_2020Sep srusa_founders_2020Sep spolice_threat_2020Sep sinternetharass_dem_2020Sep {
    replace `var' = 0 if missing(`var')
}

* Initialize the total score and the count of non-zero responses
gen total_scoreSJV = 0
gen count_nonzeroSJV = 0

* Add each variable to the total scale score and count it if non-zero
foreach var in sft_blm_2020Sep srreparations_2020Sep srdefundpolice_2020Sep srusa_founders_2020Sep spolice_threat_2020Sep sinternetharass_dem_2020Sep {
    replace total_scoreSJV = total_scoreSJV + `var'
    replace count_nonzeroSJV = count_nonzeroSJV + (`var' != 0)
}

* Calculate the average score, avoiding division by zero
gen SocJusValues = .
replace SocJusValues = total_scoreSJV / count_nonzeroSJV if count_nonzeroSJV > 0

// Economic variables
*Delete missing values
foreach var in econtrend_2020Sep persfinretro_2020Sep finance_savings_2020Sep {
    replace `var' = . if `var' > 3
}

foreach var in finance_event_lost_job_2020Sep finance_event_spouse_job_2020Sep finance_event_rent_2020Sep finance_event_loan_2020Sep finance_event_car_2020Sep finance_event_credit_2020Sep finance_event_income_2020Sep { // heavy not applicable for many of the questions, av about 25% but varies
    replace `var' = . if `var' > 2
}

replace faminc_2020Sep=. if faminc_2020Sep==97
 
*Generate dummies
gen unemployed=.
replace unemployed=1 if inlist(employment_2020Sep, 3, 4)
replace unemployed=0 if inlist(employment_2020Sep, 1, 2)

*Reverse coding so economic precarity is coded low
foreach var in econtrend_2020Sep persfinretro_2020Sep finance_savings_2020Sep finance_unexpected_2020Sep unemployed {
    qui sum `var'
    local max_value = r(max)
    gen r`var' = `max_value' + 1 - `var'
}

// Correlations
pwcorr SocJusValues recontrend_2020Sep rpersfinretro_2020Sep rfinance_savings_2020Sep finance_event_income_2020Sep finance_event_credit_2020Sep finance_event_car_2020Sep finance_event_loan_2020Sep finance_event_rent_2020Sep finance_event_spouse_job_2020Sep finance_worry_2020Sep rfinance_unexpected_2020Sep finance_event_lost_job_2020Sep runemployed faminc_2020Sep [aweight=weight_genpop_2020Sep], sig
	   
log close





